import {
	ref,
	onMounted,
	watch
} from 'vue'



export default function(fetch, ) {

	let article_ref = ref(null)
	let innerHeight = ref(0)
	let status = ref('more'); //  
	onMounted(function() {


		// window.

		// setTimeout(v=>{

		// 	console.log(article_ref.value.scrollHeight)
		// },1500)

		watch(() => article_ref.value.scrollHeight, function(n) {
			nextTick(function() {
				console.log(article_ref.value.scrollHeight)
				innerHeight.value = article_ref.value.scrollHeight
			})

		});



		window.onscroll = function() {
			let top = document.documentElement.scrollTop;

			if (status.value === 'loading' || status.value === 'onmore') {

				return
			}
			// console.log(top)
			if (top >= innerHeight.value - 100 - window.innerHeight && status.value === 'more') {

				// console.log('快到底了'+innerHeight.value)
				// 调用新数据
				status.value = 'loading'
				fetch()

			}
		}


	})

	return {
		article_ref,
		status
	}

}